import { defineStore } from "pinia"

import { reactive } from "vue"
export const useItemInfoStore = defineStore("itemInfo", () => {
  const orderInfo = reactive({
    address: '默认地址',
    itemList: [
      { name: '苹果', price: 20, count: 0 },
      { name: '香蕉', price: 12, count: 0 },
      { name: '梨子', price: 15, count: 0 },
    ]
  })
  const subCount = (index) => {
    if (orderInfo.itemList[index].count <= 0) {
      alert("数量不能低于0")
    } else {
      orderInfo.itemList[index].count--
    }

  }
  const addCount = (index) => {
    orderInfo.itemList[index].count++
  }
  return { orderInfo, subCount, addCount }
})